//package com.wxzz.elearning.gateway.controller;
//
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.wxzz.elearning.common.bean.ResponseData;
//import com.wxzz.elearning.common.jgenum.ResponseMsgCode;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.gateway.config.GatewayProperties;
//import org.springframework.cloud.gateway.route.RouteDefinition;
//import org.springframework.cloud.gateway.support.NameUtils;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.List;
//import java.util.stream.Collectors;
//
///**
// * Description :获取微服务包路由配置
// * <p>
// * Created by on 2020/11/2 10:16.
// */
//@RestController
//@RequestMapping("/services")
//@Api("微服务包路由配置")
//public class ServicesRouteController {
//    @Autowired
//    public RedisTemplate redisTemplate;
//
//    @Autowired
//    private GatewayProperties gatewayProperties;
//
//    @RequestMapping(value = "/find-service-route", method = {RequestMethod.POST, RequestMethod.GET})
//    @ApiOperation("获取微服务包路由配置")
//    public ResponseData findServiceRoute() {
//        JSONArray result = new JSONArray();
//        List<RouteDefinition> routeDefinitionList = gatewayProperties.getRoutes();
//        routeDefinitionList.forEach(routeDefinition -> {
//            String id = routeDefinition.getId();
//            String serviceName = routeDefinition.getUri().toString().replace("lb://","");
//            String serviceCode = serviceName.substring(0, serviceName.indexOf("-"));
//            String prefix = routeDefinition.getPredicates().stream()
//                    .filter(predicateDefinition -> ("Path").equalsIgnoreCase(predicateDefinition.getName()))
//                    .collect(Collectors.toList()).get(0).getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0")
//                    .replace("/**", "");
//            Integer stripPrefix = Integer.valueOf(routeDefinition.getFilters().stream()
//                    .filter(filterDefinition -> ("StripPrefix").equalsIgnoreCase(filterDefinition.getName()))
//                    .collect(Collectors.toList()).get(0).getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0"));
//            JSONObject jsonObject = new JSONObject();
//            jsonObject.fluentPut("serviceName", serviceName).fluentPut("serviceCode", serviceCode).fluentPut("routeId", id)
//                    .fluentPut("prefix", prefix).put("stripPrefix", stripPrefix);
//            result.add(jsonObject);
//
//        });
//        return new ResponseData(ResponseMsgCode.SUCCESS.msgCode,result,redisTemplate);
//    }
//}
